﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RegexBuilder.Extentions
{
    internal static class EscapeCharacterExtention
    {
        /// <summary>
        /// 转义特殊字符
        /// </summary>
        /// <param name="character"></param>
        /// <returns></returns>
        public static string CharToEscape(this char character)
        {
            return character switch
            {
                '?' => @"\?",
                '*' => @"\*",
                '{' => @"\{",
                '}' => @"\}",
                '[' => @"\[",
                ']' => @"\]",
                '.' => @"\.",
                '+' => @"\+",
                '(' => @"\(",
                ')' => @"\)",
                '^' => @"\^",
                '$' => @"\$",
                '|' => @"\|",
                '\r' => @"\r",
                '\n' => @"\n",
                '\t' => @"\t",
                _ => character.ToString(),
            };
        }
    }
}
